import {
    toast,
    promptBox
} from 'nc-lightapp-front';

import deleteRows from '../../request-functions/deleteRows';

import language from '../../language';

export default function () {
    const {
        editTable: {
            deleteTableRowsByRowId
        }
    } = this.props;

    const {
        selectedRows
    } = this.state;

    let postData = [];
    selectedRows.map((item) => {
        postData.push(item.data.values.pk_psnjob.value);
    });
    if (selectedRows.length > 0) {
        promptBox({
            color: "warning",
            title: language['hi6007-000008'],/* 国际化处理： 提示*/
            content: language['hi6007-000059'],/* 国际化处理： 确定要删除所选数据吗？*/
            beSureBtnClick: async () => {
                try {
                    let res = await deleteRows({
                        param_str: postData.join(','),
                        func_type: '2'
                    });
                    if (res.success) {
                        toast({
                            color: 'success',
                            content: language['hi6007-000006']/* 国际化处理： 删除成功*/
                        });
                        selectedRows.map((item) => {
                            setTimeout(() => {
                                deleteTableRowsByRowId('ncc60071701list', item.data.rowid, true);
                            }, 1);
                        });
                    }
                } catch (e) {
                
                }
            }
        });
    }
    else if(selectedRows.length <= 0) {
        toast({
            color: 'danger',
            content: language['hi6007-000164']
        });
    }
}
